<template>
	<view class="contianer">
		<z-paging ref="paging" v-model="dataList" @query="queryList"
			empty-view-img="../../static/img/nullData.png" empty-view-text="暂无数据">
			<!-- 头部固定 -->
			<view slot="top">
				<u-tabs :list="tablist" @change="changeTab" :inactiveStyle="{color: '#999'}"
					:activeStyle="{color: 'var(--echo-main-color)'}" lineColor="var(--echo-main-color)"></u-tabs>
			</view>
			<view class="" v-if="tabItemIndex == 0">
				<order-card v-for="item in dataList" :item="item" componentOrderType='transfer'></order-card>
			</view>
			<view class="" v-if="tabItemIndex == 1">
				<order-card v-for="item in dataList" :item="item" componentOrderType='purchase'></order-card>
			</view>
			<view class="" v-if="tabItemIndex == 2">
				<order-card v-for="item in dataList" :item="item" componentOrderType='refund'></order-card>
			</view>
			<view class="" v-if="tabItemIndex == 3">
				<order-card v-for="item in dataList" :item="item" componentOrderType='recharge'></order-card>
			</view>
		</z-paging>
	</view>
</template>

<script>
	import {
		getOrderPageList
	} from '@/config/orderApi.js';
	export default {
		data() {
			return {
				// 请求的数据
				dataList: [],
				// tab切换内容
				tablist: [{
						name: '转让',
					},
					{
						name: '购买',
					}, {
						name: '退款',
					},
					{
						name: '充值',
					}
				],
				// tab切换
				tabItemIndex: 0,
				tenantId: '',
				customerNo: ''
				// customerNo: "1518474394966560768",
			}
		},
		created() {
			// 客户编号
			this.tenantId = getApp().globalData.tenantId
			this.customerNo = uni.getStorageSync('customerNo')
		},
		methods: {
			changeTab(item) {
				// console.log(item.index)
				this.tabItemIndex = item.index
				this.$refs.paging.reload();
			},
			queryList(pageNo, pageSize) {
				if (this.tabItemIndex == 0) {
					getOrderPageList({
						pageNo,
						pageSize,
						customerNo: this.customerNo,
						tenantId: this.tenantId,
						orderType: '7'
					}).then(res => {
						if (res) {
							console.log('转让', res)
							this.$refs.paging.completeByTotal(res?.data, res?.pagination?.totalSize);
						}
					})
				} else if (this.tabItemIndex == 1) {
					getOrderPageList({
						pageNo,
						pageSize,
						customerNo: this.customerNo,
						tenantId: this.tenantId,
						orderType: '0'
					}).then(res => {
						if (res) {
							console.log('购买', res)
							this.$refs.paging.completeByTotal(res?.data, res?.pagination?.totalSize);
						}
					})
				} else if (this.tabItemIndex == 2) {
					getOrderPageList({
						pageNo,
						pageSize,
						customerNo: this.customerNo,
						tenantId: this.tenantId,
						orderType: '1'
					}).then(res => {
						if (res) {
							console.log('退款', res)
							this.$refs.paging.completeByTotal(res?.data, res?.pagination?.totalSize);
						}
					})
				} else {
					getOrderPageList({
						pageNo,
						pageSize,
						customerNo: this.customerNo,
						tenantId: this.tenantId,
						orderType: '3'
					}).then(res => {
						if (res) {
							console.log('充值', res)
							this.$refs.paging.completeByTotal(res?.data, res?.pagination?.totalSize);
						}
					})
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		/* 确保没有高度的时候也会100% */
		min-height: 100vh;
		background-color: var(--echo-main-page-bg-color);
	}
</style>
